package com.tuozixuan.spring6.resources;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import com.tuozixuan.spring6.resouceloader.TestBean;

public class Demo4 {

	public static void main(String[] args) {
		// Spring容器会将一个ResourceLoader对象作为该方法的参数传入
		ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");
		TestBean testBean = ctx.getBean("testBean", TestBean.class);
		// 获取ResourceLoader对象
		ResourceLoader resourceLoader = testBean.getResourceLoader();
		System.out.println("Spring容器将自身注入到ResourceLoaderAware Bean 中 ？ ：" + (resourceLoader));
		// 加载其他资源
		Resource resource = resourceLoader.getResource("note.txt");
		System.out.println(resource.getFilename());
		System.out.println(resource.getDescription());
	}
}
